package com.bkgy.modular.configureRules.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.configureRules.dto.SimulatedFriction1720Dto;
import com.bkgy.modular.configureRules.entity.SimulatedFriction1720;
import com.bkgy.modular.configureRules.mapper.SimulatedFriction1720Mapper;
import com.bkgy.modular.configureRules.service.SimulatedFriction1720Service;
import com.bkgy.sys.common.entity.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName SimulatedFriction1720Impl
 * @date 2023/4/20 11:27
 */
@Service
public class SimulatedFriction1720Impl extends ServiceImpl<SimulatedFriction1720Mapper, SimulatedFriction1720> implements SimulatedFriction1720Service {
    @Resource
    private SimulatedFriction1720Mapper mapper;

    @Override
    public ResultData querySimulatedFriction1720(JSONObject jsonObject) {
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        Integer pageSize = jsonObject.getInteger("pageSize");
        if (pageIndex == null || pageSize == null) {
            return ResultData.ResultDataFaultSelf("分页参数不能为空",-1);
        }

        PageHelper.startPage(pageIndex,pageSize);
        List<SimulatedFriction1720> selectList = mapper.selectList(null);
        PageInfo<SimulatedFriction1720> pageInfo = new PageInfo<>(selectList);
        return ResultData.ResultDataFaultSelf("操作成功",pageInfo);
    }

    @Override
    public ResultData updateSimulatedFriction1720(SimulatedFriction1720Dto dto) {
        Double id = dto.getId();
        if (id == null) {
            return ResultData.ResultDataFaultSelf("必传参数有误",-1);
        }
        String roll_type = dto.getRoll_type();
        Double oil_type = dto.getOil_type();
        Double coolant_mode = dto.getCoolant_mode();
        Double std = dto.getStd();
        Double myu0 = dto.getMyu0();
        Double myu1 = dto.getMyu1();
        Double myu2 = dto.getMyu2();
        Double myu3 = dto.getMyu3();
        Double strip_surface = dto.getStrip_surface();

        LambdaQueryWrapper<SimulatedFriction1720> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SimulatedFriction1720::getId,id);

        SimulatedFriction1720 simulatedFriction1720 = mapper.selectOne(queryWrapper);
        if (simulatedFriction1720 != null) {
            simulatedFriction1720.setRoll_type(roll_type);
            simulatedFriction1720.setOil_type(oil_type);
            simulatedFriction1720.setCoolant_mode(coolant_mode);
            simulatedFriction1720.setStd(std);
            simulatedFriction1720.setMyu0(myu0);
            simulatedFriction1720.setMyu1(myu1);
            simulatedFriction1720.setMyu2(myu2);
            simulatedFriction1720.setMyu3(myu3);
            simulatedFriction1720.setStrip_surface(strip_surface);
            int flag = mapper.update(simulatedFriction1720, queryWrapper);
            if (flag == 1) {
                return ResultData.ResultDataFaultSelf("操作成功",1);
            }
        }
        return ResultData.ResultDataFaultSelf("操作失败",-1);
    }
}
